import { Provide, Get, Inject, Post, Body } from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core';
import { UserNotifyService } from '../../service/notify';
import { Context } from 'egg';

/**
 * 描述
 */
@Provide()
@CoolController()
export class NotifyController extends BaseController {
  @Inject()
  userNotifySrv: UserNotifyService;

  @Inject()
  ctx: Context;
 
  /**
   * 已读
   * @param ids
   * @param isRead 状态 1：已读 2：未读
   * @returns
   */
  @Post('/read')
  async read(@Body() ids: number[], @Body() isRead: number) {
    try {
        await this.userNotifySrv.read(ids, isRead, this.ctx.user.id)
        return this.ok();
    } catch (error) {
        return this.fail(error);
    }
  }

  @Get('/count')
  async count() {
    return this.ok(await this.userNotifySrv.unCount(this.ctx.user.id));
  }
}
